<?php

namespace plugin\seckill\event;

use support\spark\model\order\OrderDetail;
use plugin\seckill\app\api\service\OrderService;
use plugin\seckill\app\model\SeckillOrder;

class SeckillStock
{
    /**
     *  扣除秒杀库存
     * @param $param
     * @return bool
     */
    public function handle($param)
    {
        $orderDetail = (new OrderDetail())->getInfoByWhere([
            'order_id' => $param['id']
        ], ['rule','cart_num']);

        $seckillInfo = (new SeckillOrder())->getInfoByWhere([
            'order_id' => $param['id']
        ], ['seckill_id']);

        $orderInfo = [
            'seckill_id' => $seckillInfo['seckill_id'],
            'sku' => $orderDetail['rule'],
            'num' => $orderDetail['cart_num']
        ];

        return (new OrderService())->dealStockAndSales($orderInfo);
    }
}
